<?php
/**
 * Zhub - A PHP Framework For API Developer
 *
 * This file is part of the Zhub package.
 *
 * (c) YiLong Fan <fantiq@163.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author fanyilong <fantiq@163.com>
 * @copyright 2017 fanyilong. All rights reserved.
 * @package Zhub
 * @date 18-2-11
 */

namespace Zhub\Utils;


class Str
{
    const TYPE_ALPHA_LOWER = "";
    const TYPE_ALPHA_UPPER = "";
    const TYPE_ALPHA = "";
    const TYPE_NUMBER = "";
    const TYPE_ALPHA_NUMBER = "";

    const WORD_SEPARATOR = '-_ ';

    public static function toLowerCamelCase(string $str):string
    {
        $str = self::toUpperCamelCase($str);
        $str[0] = strtolower($str[0]);
        return $str;
    }
    public static function toUpperCamelCase(string $str):string
    {
        $str = ucwords($str, self::WORD_SEPARATOR);
        return str_replace(str_split(self::WORD_SEPARATOR), '', $str);
    }

    public static function isStartWith(string $str, string $char, bool $ignoreCase = false):bool
    {
        $method = $ignoreCase ? 'stripos' : 'strpos';
        return $method($str, $char) === 0;
    }

    public static function isEndWith(string $str, string $char, bool $ignoreCase = false):bool
    {
        $method = $ignoreCase ? 'stripos' : 'strpos';
        return $method($str, $char) === strlen($str);
    }

    public static function toArray(string $str)
    {
        return str_split($str);
    }

    public static function random(int $len = 6, ...$type)
    {
        $str = '';
        $charList = "abcdefghijklmnopqrstuvwxyz";
        $length = strlen($charList);
        $charList = str_split($charList);
        shuffle($charList);
        for($i = 0; $i < $len; $i++) {
            $str .= $charList[$length-1];
        }
        return $str;
    }
}
